<?php

class WebUser extends CWebUser
{
	const FLASH_ERROR = 'error';
	const FLASH_INFO = 'info';
	const FLASH_NOTICE = 'warning';
	const FLASH_SUCCESS = 'success';

	/**
	 * @property User the model for the logged in user.
	 */
	protected $_model;

	/**
	 * @return bool whether the logged in user is an administrator.
	 */
	public function getIsAdmin()
	{
		if (!$this->getIsGuest())
		{
			$user = $this->loadModel();
			return (boolean) $user->admin;
		}

		return false;
	}

	/**
	 * Returns the model for the logged in user.
	 * @return User the model.
	 */
	public function loadModel()
	{
		if ($this->_model !== null)
			return $this->_model;

		return $this->_model = User::model()->findByPk($this->getId());
	}
}
